# 类属性经常用于存储类中的常量
# class Circle(object):
#     pi = 3.14
#     def __init__(self,radius):
#         self.radius = radius
#
#     def area(self):
#         area = Circle.pi * (self.radius ** 2)
#         return area
#
# c = Circle(1)
# print(c.area())

# 用于定义默认值
# class Person(object):
#     pay = 8
#
#     def __init__(self,salary=None):
#         if salary:
#             self.salary = salary
#         else:
#             self.salary = Person.pay
#
# andy = Person(10)
# print(andy.salary)
#
# jack = Person()
# print(jack.salary)

# 追踪所有实例的给定值
class Person(object):
    all_peron = []
    def __init__(self,name):
        self.name = name
        Person.all_peron.append(self)

andy = Person('Andy')
jack = Person('Jack')
print(Person.all_peron)
print(Person.all_peron[0].name)
print(Person.all_peron[1].name)
